﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server
{
    class SavedFiles
    {
        List<string> files = new List<string>();

        public void RefreshFiles()
        {
            string[] entries = Directory.GetFiles("SavedFiles/");
            files.Clear();
            foreach (string fileName in entries)
            {
                files.Add(Path.GetFileName(fileName));
            }
            printFilesInDebug();
        }

        private void printFilesInDebug()
        {
            foreach(string s in files)
            {
                System.Diagnostics.Debug.WriteLine(s);
            }
        }

        public string getAllFilesInString()
        {
            StringBuilder sb = new StringBuilder();
            foreach(string s in files)
            {
                sb.Append(s + '$');
            }
            return sb.ToString();
        }

        public FileStream getFileStream(string filePath)
        {
            return new FileStream(filePath, FileMode.Open, FileAccess.Read);
        }

        public List<string> getFiles()
        {
            return files;
        }
    }
}
